package com.hspedu.hspmybatis.sqlsession;

import com.hspedu.hspmybatis.config.Function;
import com.hspedu.hspmybatis.config.MapperBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.List;

public class HspMapperProxy implements InvocationHandler {
  private HspSqlSession hspSqlSession;
  private String  mapperFile;
  private HspConfiguration hspConfiguration;

    public HspMapperProxy(HspSqlSession hspSqlSession, Class clazz, HspConfiguration hspConfiguration) {
        this.hspSqlSession = hspSqlSession;
        String name = clazz.getName();
        System.out.println("clazz.getName()==="+name);
        this.mapperFile = clazz.getSimpleName()+".xml";
        this.hspConfiguration = hspConfiguration;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        MapperBean mapperBean = hspConfiguration.read(this.mapperFile);
        if (!method.getDeclaringClass().getName().equals(mapperBean.getInterfaceName())){
            return null;
        }
        List<Function> functions = mapperBean.getFunctions();
        if (null!=functions&& 0!=functions.size()){
            for (Function function : functions) {
                if (method.getName().equals(function.getFuncName())){
                    if ("select".equals(function.getSqlType())){

                    }
                }
            }
        }

        return null;
    }


}
